<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title></title>
    <#include "/inc/head.ftl"/>
    <@head/>
</head>

<body>
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="row">
                <div class="col-lg-12">
                    <form id="form" action="${contextPath}/user/register" method="post">
                        <div class="form-group">
                            <label>用户名</label>
                            <input id="name" name="user.name" value="${(user.name)!}" class="form-control" autofocus>
                        </div>

                        <div class="form-group">
                            <label>密码</label>
                            <input id="password" type="password" name="user.password" value="${(user.password)!}" class="form-control" onkeyup="validate()">
                        </div>
                        <div class="form-group">
                            <label>重复密码</label><span id="tips"></span>
                            <input id="passwordRepeat" type="password" class="form-control" onkeyup="validate()">
                        </div>
                        <div align="right">
                            <button id="btn-submit" type="submit" class="btn btn-default" disabled="disabled">提交</button>
                            <button id="btn-reset" type="reset" class="btn btn-default">重置</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- /.panel-body -->
    </div>
    <!-- /.panel -->

    <script>
        $(function() {
            $('form').validate({
                submitHandler: function(form) {
                    $(form).ajaxSubmit(function(data) {
                        if (data.result) {
                            parent.layer.msg(data.msg, {
                                time: 1000,
                                icon: 1
                            });
                        } else {
                            parent.layer.msg(data.msg, {
                                time: 1000,
                                icon: 2
                            });
                        }
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                    });
                }
            });
        });

        /* jquery判断两次输入密码是否相同。 */
        function validate() {
            var pwd = $("#password").val();
            var pwd1 = $("#passwordRepeat").val();
            if (pwd == pwd1) {
                $("#tips").html("两次密码相同");
                $("#tips").css("color", "green");
                $("#btn-submit").removeAttr("disabled");
            } else {
                $("#tips").html("两次密码不相同");
                $("#tips").css("color", "red")
                $("#btn-submit").attr("disabled", "disabled");
            }
        }
    </script>
</body>

</html>